package com.comba.patch.tool.utils;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import com.google.common.hash.Hashing;

public abstract class PatchUtils {
	private PatchUtils() {}

	public static String md5(File file) throws IOException {
		byte[] input = FileUtils.readFileToByteArray(file);
		return Hashing.md5().hashBytes(input).toString();
	}

	public static long fileLength(File file) {
		return file.length();
	}

	public static String getRelativePath(File dir, File file) {
		return file.getPath().substring(dir.getPath().length() + 1);
	}

	public static double formatDouble(double value) {
		java.text.DecimalFormat   df   =new   java.text.DecimalFormat("#.000");
		return Double.parseDouble(df.format(value));
	}
}
